//
//  TTRecyclingPayOrderViewController.m
//  TaoTuo
//
//  Created by LG on 2020/9/14.
//  Copyright © 2020 刘广. All rights reserved.
//

#import "TTRecyclingPayOrderViewController.h"
#import "TTCommitSuccessViewController.h"
#import "TTZFBPayTool.h"
#import "TTRecyclingMyBuyViewController.h"

@interface TTRecyclingPayOrderViewController ()

@property (nonatomic, copy) NSString *title;
@property (nonatomic, copy) NSString *subTitle;

@end

@implementation TTRecyclingPayOrderViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
}

// 获取支付信息
- (void)getPaymentInfo
{
    NSDictionary *dic = @{
        @"param.orderNo" : self.orderNum,
    };
    
    [[LLNetworkManagerTool sharedManager] requestMethod:GET urlString:recyclingGetPayInfo_api parameters:dic success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        
        NSMutableArray *arr = [NSMutableArray array];
        for (NSDictionary *dic in responseObject) {
            TTPayOrderModel *model = [TTPayOrderModel modelWithJSON:dic];
            [arr addObject:model];
        }
        [self setupDatasWithPayListArray:arr];
        
    } failure:^(NSURLSessionDataTask * _Nonnull task, NSError * _Nullable error) {
        
    } showLoadingInView:self.view];
}

- (void)setupTitle:(NSString *)title subTitle:(NSString *)subTitle
{
    self.title = title;
    self.subTitle = subTitle;
}

// 支付
- (void)payBtnClick
{
    TTZFBPayModel *model = [[TTZFBPayModel alloc] init];
    model.paymentBusines = @"4";
    model.callWay = @"0";
    model.no = self.orderNum;
    model.type = self.selectOrderModel.PayType;
    model.platformUserAccount = [TTLoginSingle sharedSingle].loginModel.Mobile;
    model.platformUserName = [TTLoginSingle sharedSingle].loginModel.Name;
    model.serviceMoney = self.selectOrderModel.ServiceMoney;
    model.serviceMoneyPercent = self.selectOrderModel.ServiceMoneyPercent;
    model.goodsTitle = self.title;
    model.goodsTitleSub = self.subTitle;
    model.paymentType = @"2";
    model.paymentMethod = @"1";
    model.payAmount = self.selectOrderModel.PayMoney;
    NSDictionary *dic = [model modelToDic];
    
    [TTZFBPayTool createOrderNumberWithParams:dic notifyKey:shopPaySuccessKey];
    

    
}


- (void)addPayResultNotify
{
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(recyclingShopPaySuccessNotify:) name:recyclingShopPaySuccessKey object:nil];
}

- (void)gotoSuccessPage
{
    [self.navigationController popViewControllerAnimated:YES];
}

/// 暂不支付
- (void)notPayBtnClick
{
    [self.navigationController popViewControllerAnimated:YES];
}

/// 支付成功
- (void)recyclingShopPaySuccessNotify:(NSNotification *)notify
{
    NSMutableArray *vcs = [NSMutableArray array];
    for (UIViewController *vc in self.navigationController.viewControllers) {
        if ([vc isKindOfClass:NSClassFromString(@"TTRecyclingCommitOrderViewController")] || [vc isKindOfClass:[TTRecyclingPayOrderViewController class]]) {
            continue;
        }
        [vcs addObject:vc];
    }
    self.navigationController.viewControllers = vcs;
    
    TTRecyclingMyBuyViewController *listVC = [[TTRecyclingMyBuyViewController alloc] init];
    listVC.defaultIndex = 1;
    [[LLRouteTool getCurrentNavigationController] pushViewController:listVC animated:YES];
    
}

@end
